﻿using System;
using UnityEngine;

// Token: 0x020002E5 RID: 741
public class WaterHelper : MonoBehaviour
{
	// Token: 0x0600112F RID: 4399 RVA: 0x0007F0B4 File Offset: 0x0007D2B4
	private void Start()
	{
		this.mat = base.GetComponent<MeshRenderer>().material;
		this.cam = Camera.main.transform.parent;
		this.waterPlane = base.transform;
		this.aquasReflection = base.GetComponent<AQUAS_Reflection>();
		this.UpdateGraphicSettings();
	}

	// Token: 0x06001130 RID: 4400 RVA: 0x0007F108 File Offset: 0x0007D308
	private void Update()
	{
		if (!this.neverUseReflections)
		{
			float y = this.cam.localScale.y;
			if (y > this.maxScale && this.reflexionsEnabled)
			{
				this.SetRelections(false);
				this.reflexionsEnabled = false;
			}
			else if (y < this.maxScale && !this.reflexionsEnabled)
			{
				this.SetRelections(true);
				this.reflexionsEnabled = true;
			}
		}
		float y2 = this.cam.position.y;
		float y3 = this.waterPlane.position.y;
		if (y2 > y3 && this.underWater)
		{
			this.mat.SetFloat("_UnderwaterMode", 0f);
			this.underWater = false;
		}
		else if (y2 < y3 && !this.underWater)
		{
			this.mat.SetFloat("_UnderwaterMode", 0.6f);
			this.underWater = true;
		}
	}

	// Token: 0x06001131 RID: 4401 RVA: 0x0007F210 File Offset: 0x0007D410
	public void UpdateGraphicSettings()
	{
		this.aquasReflection.m_ReflectLayers = Layers.reflectionMask;
		switch (QualitySettings.GetQualityLevel())
		{
		default:
			this.neverUseReflections = true;
			this.SetRelections(false);
			this.SetTextureSize(128);
			break;
		case 1:
			this.SetTextureSize(128);
			break;
		case 2:
		case 3:
			this.SetTextureSize(256);
			break;
		case 4:
			this.SetTextureSize(512);
			break;
		case 5:
			this.SetTextureSize(1024);
			break;
		}
	}

	// Token: 0x06001132 RID: 4402 RVA: 0x0007F2B4 File Offset: 0x0007D4B4
	private void SetRelections(bool enabled)
	{
		if (enabled)
		{
			this.mat.SetFloat("_EnableReflections", 0.6f);
		}
		else
		{
			this.mat.SetFloat("_EnableReflections", 0f);
		}
	}

	// Token: 0x06001133 RID: 4403 RVA: 0x0007F2EB File Offset: 0x0007D4EB
	private void SetTextureSize(int size)
	{
		this.aquasReflection.m_TextureSize = size;
	}

	// Token: 0x040016A4 RID: 5796
	private const string cEnableReflections = "_EnableReflections";

	// Token: 0x040016A5 RID: 5797
	private const string cUnderwaterMode = "_UnderwaterMode";

	// Token: 0x040016A6 RID: 5798
	private AQUAS_Reflection aquasReflection;

	// Token: 0x040016A7 RID: 5799
	private Material mat;

	// Token: 0x040016A8 RID: 5800
	private bool reflexionsEnabled = true;

	// Token: 0x040016A9 RID: 5801
	private bool neverUseReflections;

	// Token: 0x040016AA RID: 5802
	private bool underWater;

	// Token: 0x040016AB RID: 5803
	private Transform cam;

	// Token: 0x040016AC RID: 5804
	private Transform waterPlane;

	// Token: 0x040016AD RID: 5805
	private float maxScale = 80f;
}
